﻿Public Class frmTKMatHang

    Private Sub frmTKMatHang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgvDanhSachMatHang.DataSource = CKiemTra.LoadDS("select * from SANPHAM")
        cbxLoaiMH.DataSource = CKiemTra.LoadDS("select * from LOAISANPHAM")
        cbxLoaiMH.DisplayMember = "TenLoai"
        cbxLoaiMH.ValueMember = "MaLoai"
    End Sub

    Private Sub cbxLoaiMH_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxLoaiMH.SelectedIndexChanged
        dgvDanhSachMatHang.DataSource = CKiemTra.LoadDS("select * from SANPHAM where MaLoai = '" + cbxLoaiMH.SelectedValue.ToString() + "'")
    End Sub

    Private Sub btnTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiem.Click
        Dim sql = "select * from SANPHAM where TenSanPham like N'%" + txtTenMH.Text + "%' and MaLoai = '" + cbxLoaiMH.SelectedValue.ToString() + "'"
        dgvDanhSachMatHang.DataSource = CKiemTra.LoadDS(sql)
    End Sub
End Class